from game import zz_game
from zz import zz_log, zz_img

log = zz_log.of()


class Game(zz_game.ZZ_Game):
    def __init__(self, d, has_prize=True):
        super().__init__(d, has_prize)

    def get_name(self):
        return "向僵尸开炮"

    def game_alert(self):
        self.alert_close_by_file('./game/img/向僵尸开炮')

    def play_alert(self):
        if not self.img_exit('./game/img/向僵尸开炮/play_alert.png', 2):
            self.log_msg("无选择弹窗", False)
            return

        self.log_msg("存在选择弹窗，点击选择", False)
        w, h = self.d.window_size()
        self.d.click(w / 2, h / 2)

    def handle_main(self):
        self.done_close()

        self.game_alert()
        self.log_msg("等待进入游戏主界面")
        self.img_exit('./game/img/向僵尸开炮/game_main.png', 100)
        self.log_msg("已进入游戏主界面")

        if self.not_prize_handle():
            return False

        for i in range(2):
            self.game_alert()
            self.click_bottom()
            self.swipe_right(0.2)

            self.img_click_for('开始进入战斗', './game/img/向僵尸开炮/play_start.png')
            if self.img_exit('./game/img/向僵尸开炮/play_01.png', 2):
                self.log_msg(f"点击继续挑战")
                self.img_click('./game/img/向僵尸开炮/play_01.png')
            self.log_msg(f"等待进入战斗界面")
            self.img_exit('./game/img/向僵尸开炮/play_main.png', 20)
            self.log_msg(f"已进入战斗界面")

            while True:
                if self.img_exit('./game/img/向僵尸开炮/play_back.png', 2):
                    break

                self.play_alert()

            self.log_msg(f"战斗结束，点击确定")
            self.img_click('./game/img/向僵尸开炮/play_back.png')

        return True
